<?php

namespace app\index\controller;
use think\Db;
use \think\Cookie;
use \think\Model;
use think\Session;
class User extends Model
{
    protected $createTime = 'regtime';
    protected $updateTime = 'lasttime';
}
class Reg extends \think\Controller
{
    public function register()
    {
        //获取请求变量
        if (input('param.')) {
            //输入数据
            $in_put = input('param.');
            $search = new User();
            $search_data = $search->whereOr('name', $in_put['name'])->whereOr('phone', $in_put['phone'])->whereOr('qq', $in_put['qq'])->find();
            if ($search_data) {
                $this->error('用户存在了哦');
            } else {
                if (mb_strwidth($in_put['password']) < 6) {
                    $this->error('密码太短了哦，请输入大于6位的密码');
                }
                $ylnuser = new User;
                $ylnuser->data([
                    'name' => $in_put['name'],
                    'mail' => $in_put['mail'],
                    'password' => md5($in_put['password']),
                    'phone' => $in_put['phone'],
                    'qq' => $in_put['qq'],
                    'city' => 'CHINA',
                    'birth' => '2000-01-01',
                    'reminder' => 0,
                    'status' => 1,
                    'safecode' => '00000000000000000000'
                ]);
                if ($ylnuser->save()) {
                    $this->success('注册成功，正在前往登录页面', '../../index/Login/login');
                }
            }
        }
        //获取数据库
        $webdate = Db::name('index')->getById(1);//根据用户识别码
        //渲染模板

        $this->assign('name', $webdate['name']);
        $this->assign('copy', $webdate['copy']);
        return $this->fetch('index/register', [], ['__PUBLIC__' => '/public/static/home']);
    }
}
